<?php
class SendMailService {
	var $dbutil;
	function __construct($dbutil) {
		$this->dbutil = $dbutil;
	}
	/**
	 * 加载实际的邮件发送者
	 */
	function getSendMails() {
		$sql = "SELECT * FROM  mail_config";
		return $this->dbutil->get_results ( $sql );
	}
	function resetCurDayMail() {
		$sql = "SELECT * FROM  mail_config where time<'".date('Y-m-d')."'";
		$items = $this->dbutil->get_results ( $sql );
		if(count($items )> 0){
			$upsql = "update  mail_config set time='".date('Y-m-d')."' , count_use = 0";
			$this->dbutil->query($upsql);
		}
	}
	/**
	 *
	 * 总结果集
	 */
	public function resourcePage($start , $page_size ,$condition){
		$limit ="";
		if($page_size){
			$limit =" limit $start,$page_size ";
		}
		$sql = "SELECT * FROM mail_config ".$limit;
		return $this->dbutil->get_results($sql);
	}
	/**
	 *
	 * 总记录数
	 */
	public function countNum() {
		$sql = "SELECT count(1) countnum FROM mail_config";
		$resutrnarry = $this->dbutil->get_results ( $sql );
		return $resutrnarry [0]->countnum;
	}
	public function addItem($data){
		return	$this->dbutil->insert("mail_config", $data);
	}
	
	public function edit($data,$conditions){
		return $this->dbutil->update("mail_config",$data,$conditions);
	}
	public function removePosts($id) {
		$sql = " delete from mail_config where id= '".$id."'";//删除子节点
		return $this->dbutil->query($sql);
	}
	public function updateMailCount($id) {
		$sql = " UPDATE  mail_config SET count_use = count_use+1 WHERE id='".$id."'";//删除子节点
		return $this->dbutil->query($sql);
	}
	
}
?>